local scene = director:createScene()

function scene:setUp(event)
    dbg.print("sceneMenu:setUp")
	
	local allScaleX = 320/director.displayWidth
	local allScaleY = 480/director.displayHeight
	
	----- Advertising
	
	if ads:isAvailable() then
		ads:newAd(director.displayHeight, 70/allScaleY, "leadbolt", "banner", "896063058")
	else
		dbg.log("Ads are not available")
	end
	
	ads:show(true)
	
	-----
	
	if (io.open("scorebeginner.txt") == nil) then
	file = io.open("scorebeginner.txt", "w")
	file:write("0".."\n")
	file:write("0".."\n")
	file:write("0".."\n")
	file:close()
	end
	
	if (io.open("scoreexpert.txt") == nil) then
	file = io.open("scoreexpert.txt", "w")
	file:write("0".."\n")
	file:write("0".."\n")
	file:write("0".."\n")
	file:close()
	end
	
    local buttonBeginner = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonBeginner.xAnchor=0.5; buttonBeginner.yAnchor=0.5
	buttonBeginner.y = director.displayCenterY + buttonBeginner.h/allScaleY
	buttonBeginner.yScale=.6/allScaleY; 
	buttonBeginner.xScale=1.1/allScaleX;
	
	labelBeginner = director:createLabel(director.displayCenterX, director.displayCenterY, "Beginner")
	labelBeginner.xAnchor=0.5; 
	labelBeginner.zOrder = buttonBeginner.zOrder
	labelBeginner. hAlignment="center"
	labelBeginner.y = buttonBeginner.y-10/allScaleY
	labelBeginner.xScale = 1/allScaleX
	labelBeginner.yScale = 1/allScaleY
	
    local buttonExpert = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonExpert.xAnchor=0.5; buttonExpert.yAnchor=0.5
	buttonExpert.y =  director.displayCenterY + buttonExpert.h/3/allScaleY
	buttonExpert.yScale=.6/allScaleY; 
	buttonExpert.xScale=1.1/allScaleX;
	
	labelExpert = director:createLabel(director.displayCenterX, director.displayCenterY, "Expert")
	labelExpert.xAnchor=0.5; 
	labelExpert.zOrder = buttonExpert.zOrder
	labelExpert. hAlignment="center"
	labelExpert.y = buttonExpert.y-10/allScaleY
	labelExpert.xScale = 1/allScaleX
	labelExpert.yScale = 1/allScaleY
	
	local buttonScore = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonScore.xAnchor=0.5; buttonScore.yAnchor=0.5
	buttonScore.y =  director.displayCenterY - buttonScore.h/allScaleY
	buttonScore.yScale=.6/allScaleY; 
	buttonScore.xScale=1.1/allScaleX;
	
	labelScore = director:createLabel(director.displayCenterX, director.displayCenterY, "Score")
	labelScore.xAnchor=0.5; 
	labelScore.zOrder = buttonScore.zOrder
	labelScore. hAlignment="center"
	labelScore.y = buttonScore.y-10/allScaleY
	labelScore.xScale = 1/allScaleX
	labelScore.yScale = 1/allScaleY
	
	local buttonInstructions = director:createSprite(director.displayCenterX, director.displayCenterY, "img/button.png")
	buttonInstructions.xAnchor=0.5; buttonInstructions.yAnchor=0.5
	buttonInstructions.y =  director.displayCenterY - buttonInstructions.h/3/allScaleY
	buttonInstructions.yScale=.6/allScaleY; 
	buttonInstructions.xScale=1.1/allScaleX;
	
	labelInstructions = director:createLabel(director.displayCenterX, director.displayCenterY, "Instructions")
	labelInstructions.xAnchor=0.5;
	labelInstructions.zOrder = buttonBeginner.zOrder
	labelInstructions. hAlignment="center"
	labelInstructions.y = buttonInstructions.y-10/allScaleY
	labelInstructions.xScale = 1/allScaleX
	labelInstructions.yScale = 1/allScaleY
	
	function buttonBeginner:touch(event)
		if (event.phase == 'began') then
			selectGame = "beginner"
			system:sendEvent("moveToSceneGame")
		end
	end
	buttonBeginner:addEventListener('touch', buttonBeginner)
	
	function buttonExpert:touch(event)
		if (event.phase == 'began') then
			selectGame = "expert"
			system:sendEvent("moveToSceneGame")
		end
	end
	buttonExpert:addEventListener('touch', buttonExpert)

	function buttonInstructions:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneInstructions")
		end
	end
	buttonInstructions:addEventListener('touch', buttonInstructions)
	
	function buttonScore:touch(event)
		if (event.phase == 'began') then
			system:sendEvent("moveToSceneScore")
		end
	end
	buttonScore:addEventListener('touch', buttonScore)
end

function scene:tearDown(event)
    dbg.print("sceneMenu:tearDown")
end

scene:addEventListener({"setUp", "tearDown"}, scene)

return scene  -- We must return the scene object!